
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 03/22/2011 11:21:22
-- Generated from EDMX file: D:\Documents\Projekter\BioBooking\BioBooking.Data\BioBooking.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [dm71_3];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_MovieGenre]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MovieSet] DROP CONSTRAINT [FK_MovieGenre];
GO
IF OBJECT_ID(N'[dbo].[FK_BookingMember]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BookingSet] DROP CONSTRAINT [FK_BookingMember];
GO
IF OBJECT_ID(N'[dbo].[FK_SeatBooking_Seat]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SeatBooking] DROP CONSTRAINT [FK_SeatBooking_Seat];
GO
IF OBJECT_ID(N'[dbo].[FK_SeatBooking_Booking]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SeatBooking] DROP CONSTRAINT [FK_SeatBooking_Booking];
GO
IF OBJECT_ID(N'[dbo].[FK_SeatCinema]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SeatSet] DROP CONSTRAINT [FK_SeatCinema];
GO
IF OBJECT_ID(N'[dbo].[FK_BookingShowing]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BookingSet] DROP CONSTRAINT [FK_BookingShowing];
GO
IF OBJECT_ID(N'[dbo].[FK_CinemaShowing]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ShowingSet] DROP CONSTRAINT [FK_CinemaShowing];
GO
IF OBJECT_ID(N'[dbo].[FK_MovieShowing]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ShowingSet] DROP CONSTRAINT [FK_MovieShowing];
GO
IF OBJECT_ID(N'[dbo].[FK_SeatStateSeat]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SeatStateSet] DROP CONSTRAINT [FK_SeatStateSeat];
GO
IF OBJECT_ID(N'[dbo].[FK_ShowingSeatState]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SeatStateSet] DROP CONSTRAINT [FK_ShowingSeatState];
GO
IF OBJECT_ID(N'[dbo].[FK_ScreenShotMovie]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ScreenShotSet] DROP CONSTRAINT [FK_ScreenShotMovie];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[MemberSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MemberSet];
GO
IF OBJECT_ID(N'[dbo].[MovieSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MovieSet];
GO
IF OBJECT_ID(N'[dbo].[BookingSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BookingSet];
GO
IF OBJECT_ID(N'[dbo].[CinemaSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CinemaSet];
GO
IF OBJECT_ID(N'[dbo].[ShowingSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ShowingSet];
GO
IF OBJECT_ID(N'[dbo].[GenreSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[GenreSet];
GO
IF OBJECT_ID(N'[dbo].[SeatSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SeatSet];
GO
IF OBJECT_ID(N'[dbo].[SeatStateSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SeatStateSet];
GO
IF OBJECT_ID(N'[dbo].[ScreenShotSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ScreenShotSet];
GO
IF OBJECT_ID(N'[dbo].[SeatBooking]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SeatBooking];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'MemberSet'
CREATE TABLE [dbo].[MemberSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [FullName] nvarchar(max)  NOT NULL,
    [Telephone] nvarchar(max)  NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [Discount] bit  NOT NULL,
    [Counter] int  NOT NULL
);
GO

-- Creating table 'MovieSet'
CREATE TABLE [dbo].[MovieSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Titel] nvarchar(max)  NOT NULL,
    [ReleaseDate] datetime  NOT NULL,
    [Instructor] nvarchar(max)  NOT NULL,
    [Actors] nvarchar(max)  NOT NULL,
    [OriginalTitle] nvarchar(max)  NOT NULL,
    [Country] nvarchar(max)  NOT NULL,
    [Language] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [isActive] bit  NOT NULL,
    [Runtime] int  NOT NULL,
    [StartDate] datetime  NOT NULL,
    [EndDate] datetime  NOT NULL,
    [Genre_Id] int  NOT NULL
);
GO

-- Creating table 'BookingSet'
CREATE TABLE [dbo].[BookingSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [CreatedDate] datetime  NOT NULL,
    [PaymentRecived] bit  NOT NULL,
    [Member_Id] int  NOT NULL,
    [Showing_Id] int  NOT NULL
);
GO

-- Creating table 'CinemaSet'
CREATE TABLE [dbo].[CinemaSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [SeatCapacity] int  NOT NULL,
    [Name] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'ShowingSet'
CREATE TABLE [dbo].[ShowingSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [StartTime] datetime  NOT NULL,
    [EndTime] datetime  NOT NULL,
    [UnitPrice] decimal(18,0)  NOT NULL,
    [Date] datetime  NOT NULL,
    [CinemaId] int  NOT NULL,
    [MovieId] int  NOT NULL
);
GO

-- Creating table 'GenreSet'
CREATE TABLE [dbo].[GenreSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'SeatSet'
CREATE TABLE [dbo].[SeatSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Row] int  NOT NULL,
    [Column] int  NOT NULL,
    [Cinema_Id] int  NOT NULL
);
GO

-- Creating table 'SeatStateSet'
CREATE TABLE [dbo].[SeatStateSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Occupied] bit  NOT NULL,
    [Locked] bit  NOT NULL,
    [ShowingId] int  NOT NULL,
    [Seat_Id] int  NOT NULL
);
GO

-- Creating table 'ScreenShotSet'
CREATE TABLE [dbo].[ScreenShotSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [MovieId] int  NOT NULL,
    [Image] varbinary(max)  NOT NULL,
    [Title] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'SeatBooking'
CREATE TABLE [dbo].[SeatBooking] (
    [Seats_Id] int  NOT NULL,
    [Bookings_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'MemberSet'
ALTER TABLE [dbo].[MemberSet]
ADD CONSTRAINT [PK_MemberSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'MovieSet'
ALTER TABLE [dbo].[MovieSet]
ADD CONSTRAINT [PK_MovieSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BookingSet'
ALTER TABLE [dbo].[BookingSet]
ADD CONSTRAINT [PK_BookingSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CinemaSet'
ALTER TABLE [dbo].[CinemaSet]
ADD CONSTRAINT [PK_CinemaSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ShowingSet'
ALTER TABLE [dbo].[ShowingSet]
ADD CONSTRAINT [PK_ShowingSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'GenreSet'
ALTER TABLE [dbo].[GenreSet]
ADD CONSTRAINT [PK_GenreSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'SeatSet'
ALTER TABLE [dbo].[SeatSet]
ADD CONSTRAINT [PK_SeatSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'SeatStateSet'
ALTER TABLE [dbo].[SeatStateSet]
ADD CONSTRAINT [PK_SeatStateSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ScreenShotSet'
ALTER TABLE [dbo].[ScreenShotSet]
ADD CONSTRAINT [PK_ScreenShotSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Seats_Id], [Bookings_Id] in table 'SeatBooking'
ALTER TABLE [dbo].[SeatBooking]
ADD CONSTRAINT [PK_SeatBooking]
    PRIMARY KEY NONCLUSTERED ([Seats_Id], [Bookings_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Genre_Id] in table 'MovieSet'
ALTER TABLE [dbo].[MovieSet]
ADD CONSTRAINT [FK_MovieGenre]
    FOREIGN KEY ([Genre_Id])
    REFERENCES [dbo].[GenreSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MovieGenre'
CREATE INDEX [IX_FK_MovieGenre]
ON [dbo].[MovieSet]
    ([Genre_Id]);
GO

-- Creating foreign key on [Member_Id] in table 'BookingSet'
ALTER TABLE [dbo].[BookingSet]
ADD CONSTRAINT [FK_BookingMember]
    FOREIGN KEY ([Member_Id])
    REFERENCES [dbo].[MemberSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BookingMember'
CREATE INDEX [IX_FK_BookingMember]
ON [dbo].[BookingSet]
    ([Member_Id]);
GO

-- Creating foreign key on [Seats_Id] in table 'SeatBooking'
ALTER TABLE [dbo].[SeatBooking]
ADD CONSTRAINT [FK_SeatBooking_Seat]
    FOREIGN KEY ([Seats_Id])
    REFERENCES [dbo].[SeatSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Bookings_Id] in table 'SeatBooking'
ALTER TABLE [dbo].[SeatBooking]
ADD CONSTRAINT [FK_SeatBooking_Booking]
    FOREIGN KEY ([Bookings_Id])
    REFERENCES [dbo].[BookingSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SeatBooking_Booking'
CREATE INDEX [IX_FK_SeatBooking_Booking]
ON [dbo].[SeatBooking]
    ([Bookings_Id]);
GO

-- Creating foreign key on [Cinema_Id] in table 'SeatSet'
ALTER TABLE [dbo].[SeatSet]
ADD CONSTRAINT [FK_SeatCinema]
    FOREIGN KEY ([Cinema_Id])
    REFERENCES [dbo].[CinemaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SeatCinema'
CREATE INDEX [IX_FK_SeatCinema]
ON [dbo].[SeatSet]
    ([Cinema_Id]);
GO

-- Creating foreign key on [Showing_Id] in table 'BookingSet'
ALTER TABLE [dbo].[BookingSet]
ADD CONSTRAINT [FK_BookingShowing]
    FOREIGN KEY ([Showing_Id])
    REFERENCES [dbo].[ShowingSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BookingShowing'
CREATE INDEX [IX_FK_BookingShowing]
ON [dbo].[BookingSet]
    ([Showing_Id]);
GO

-- Creating foreign key on [CinemaId] in table 'ShowingSet'
ALTER TABLE [dbo].[ShowingSet]
ADD CONSTRAINT [FK_CinemaShowing]
    FOREIGN KEY ([CinemaId])
    REFERENCES [dbo].[CinemaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CinemaShowing'
CREATE INDEX [IX_FK_CinemaShowing]
ON [dbo].[ShowingSet]
    ([CinemaId]);
GO

-- Creating foreign key on [MovieId] in table 'ShowingSet'
ALTER TABLE [dbo].[ShowingSet]
ADD CONSTRAINT [FK_MovieShowing]
    FOREIGN KEY ([MovieId])
    REFERENCES [dbo].[MovieSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MovieShowing'
CREATE INDEX [IX_FK_MovieShowing]
ON [dbo].[ShowingSet]
    ([MovieId]);
GO

-- Creating foreign key on [Seat_Id] in table 'SeatStateSet'
ALTER TABLE [dbo].[SeatStateSet]
ADD CONSTRAINT [FK_SeatStateSeat]
    FOREIGN KEY ([Seat_Id])
    REFERENCES [dbo].[SeatSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SeatStateSeat'
CREATE INDEX [IX_FK_SeatStateSeat]
ON [dbo].[SeatStateSet]
    ([Seat_Id]);
GO

-- Creating foreign key on [ShowingId] in table 'SeatStateSet'
ALTER TABLE [dbo].[SeatStateSet]
ADD CONSTRAINT [FK_ShowingSeatState]
    FOREIGN KEY ([ShowingId])
    REFERENCES [dbo].[ShowingSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ShowingSeatState'
CREATE INDEX [IX_FK_ShowingSeatState]
ON [dbo].[SeatStateSet]
    ([ShowingId]);
GO

-- Creating foreign key on [MovieId] in table 'ScreenShotSet'
ALTER TABLE [dbo].[ScreenShotSet]
ADD CONSTRAINT [FK_ScreenShotMovie]
    FOREIGN KEY ([MovieId])
    REFERENCES [dbo].[MovieSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ScreenShotMovie'
CREATE INDEX [IX_FK_ScreenShotMovie]
ON [dbo].[ScreenShotSet]
    ([MovieId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------